package com.edt.ichannel.api.controller;


import com.edt.ichannel.api.common.controller.BaseController;
import com.edt.ichannel.api.common.entity.ActionResult;
import com.edt.ichannel.api.service.CollectService;
import com.edt.ichannel.utils.ReadUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * CreateBy:zyp
 * CreateDate:2018/1/30
 * UpdateBy:
 * UpdateDate:
 * Description:数据收集
 **/
@Controller
@RequestMapping("/collect")
public class CollectController extends BaseController {

    @Resource
    private CollectService collectService;
    /**
     * 消费记录接收接口
     */
    @RequestMapping(value = "consume")
    @ResponseBody
    public void consume(HttpServletRequest request) throws IOException {
        //验证非post请求直接返回错误信息
        ActionResult actionResult =  collectService.validateRequestMethod(request.getMethod());
        if(!actionResult.isSuccess()){
            WriterToPageByJsonNoNull(actionResult);
        }else{
            String collectStr = ReadUtil.readRequestBody(request);
            ActionResult result = collectService.saveConsume(collectStr);
            result.setResultList(null);
            WriterToPageByJsonNoNull(result);
        }
    }




}
